package com.searchbyesandhbase.config;


import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * @author LJK
 * @description
 * @date 2024/10/27
 */
@Configuration
@Slf4j
public class HBaseConfig {
    @Value("${hbase.zookeeper.quorum}")
    private String quorum;
    @Value("${hbase.rootdir}")
    private String rootdir;
    @Bean
    public org.apache.hadoop.conf.Configuration hbaseConfiguration() {
        log.info("开始加载HBase配置...");
        org.apache.hadoop.conf.Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum",quorum);
        config.set("hbase.rootdir", rootdir);
        return config;
    }

    @Bean
    public Connection hbaseConnection(org.apache.hadoop.conf.Configuration config) throws IOException {
        return ConnectionFactory.createConnection(config);
    }
}
